<template>
  <div class="home-box">
    <header>
      <van-nav-bar
        title="详情页"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      >
      </van-nav-bar>
    </header>
    <div class="content">
      <div class="top">
        <img :src="`http://localhost:15666${img}`" alt="" />
        <div class="top-button">
          <div class="wz">
            <span>{{ list.data.description || list.data.name }}</span>
          </div>
          <div class="sc">
            <div class="tp">
              <img
                src=""
                alt=""
              />
            </div>
            <span>收藏</span>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="item-yh">
          {{ list.data.category || list.data.brandName}}
        </div>
      </div>
      <div class="like">
        <div class="like-row" v-for="item in celebrities" :key="item">
          <div class="like-tp">
            <img :src="`http://localhost:15666${item.avatar || item }`" alt="" />
          </div>
          <div class="like-wz">
            {{ item.name }}
          </div>
          <div class="like-jg">
            {{ item.role }}
          </div>
        </div>
      </div>
      <div class="db">
        <h2>到底了没有了</h2>
      </div>
    </div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon icon="cart-o" text="购物车" />
      <van-goods-action-icon icon="shop-o" text="店铺" />
      <van-goods-action-button type="warning" text="加入购物车" @click="addsApi(list)"/>
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>


<script>
  import { addApi } from '../../apis/cartApi'
export default {
  data() {
    return {
      list: [],
      celebrities: [],
      id:"",
      img:[]
    };
  },
  created() {
    this.list = JSON.parse(sessionStorage.getItem("myData"));
    this.img = this.list.data.avatar ||this.list.data.bgUrl || this.list.data.img[0]
    this.celebrities =this.celebrities.concat(this.list.data.bgUrl ||  this.list.data.celebrities || this.list.data.mobileDesc);
    this.id=this.$store.getters['common/user'].id   
  },
  methods: {
    onClickLeft() {
      this.$router.go("-1");
    },
     async addsApi(a) {
         console.log(a);
        let result = await addApi({
        userId:this.id,
        price: a.data.duration ||a.data.price,
        id: a.data.id ||a.data.brandId,
        time: Date.now(),
        count: 1,
        name:a.data.name ||a.data.price,
        detailaddress:a.data.stars ||a.data.price,
        bgUrl:a.data.avatar || a.data.img[0]
    })
    // console.log(result)
    },
  },
}
</script>


<style lang="less" scoped>
.home-box {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  background-color: #f2f2f2;
  header {
    display: block;
    width: 100%;
    height: 46px;
  }
  .content {
    position: relative;
    width: 100%;
    display: block;
    height: calc(100% - 46px - 50px);
    overflow-x: hidden;
    .top {
      width: 100%;
      height: 462px;
      background-color: #fff;
      border-radius: 15px;
      img {
        width: 100%;
        height: 390px;
        vertical-align: middle;
      }
      .top-button {
        width: 100%;
        height: 63px;
        .wz {
          float: left;
          width: 287px;
          height: 63px;
          margin-left: 10px;
          overflow: hidden;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          text-overflow: ellipsis;
          span {
            font-size: 12px;
            font-weight: 700;
            color: #262626;
          }
        }
        .sc {
          margin-top: 14px;
          float: right;
          width: 50px;
          height: 36px;
          border-left: 1px solid;
          .tp {
            margin-left: 3px;
            width: 18px;
            height: 18px;
            img {
              width: 100%;
              height: 100%;
            }
          }
          span {
            margin-left: 5px;
            font-size: 10px;
            font-weight: 700;
            color: #262626;
          }
        }
      }
    }
    .item {
      margin-top: 10px;
      width: 100%;
      height: 53px;
      border-radius: 15px;
      background-color: #fff;
      line-height: 53px;
      margin-bottom: 10px;
      .item-yh {
        margin-left: 25px;
        width: 100%;
        height: 53px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 14px;
        font-weight: 700;
        color: #e4393c;
      }
    }
    .item-button {
      margin-top: 10px;
      width: 100%;
      height: 260px;
      border-radius: 15px;
      background-color: #fff;
      .sku {
        margin-left: 24px;
        width: 339px;
        height: 76px;
        line-height: 76px;
        border-bottom: 0.5px dashed;
        .sku-top {
          width: 339px;
          height: 22px;
          h3 {
            font-size: 14px;

            span {
              margin-left: 5px;
            }
          }
        }
        .text {
          font-size: 10px;
          font-family: 400;
        }
      }
    }
    .like {
     
      width: 100%;
      height:100%;
      border-radius: 15px;
      background-color: #fff;
      display: flex;
      flex-wrap: wrap;
      justify-content:space-between;
      .like-row {
        width: 114px;
        height: 160px;       
        .like-tp {
          width: 114px;
          height: 114px;
          img {
            width: 100%;
            height:114px;
          }
        }
        .like-wz {
          width: 114px;
          height: 20px;
          text-align: center;
          font-size: 12px;
        }
        .like-jg {
          width: 114px;
          height: 20px;
          text-align: center;
          color: #e4393c;
          font-size: 12px;
        }
      }
    }
  }
  .db {
    width: 100%;
    height: 30px;
    text-align: center;
    h2 {
      font-size: 10px;
      color: darkgray;
      font-weight: 100;
    }
  }
}
</style>